//
//  BaseViewController.m
//  SkyOne4iPhone
//
//  Created by Cheung on 16/5/5.
//  Copyright © 2016年 cqrd. All rights reserved.
//

#import "BaseViewController.h"

@implementation BaseViewController


- (void)viewDidLoad {
    self.navigationController.navigationBar.hidden = NO;
   
    [self setupNavigation];
}

- (void)setupNavigation {
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *image = [UIImage imageNamed:@"backbutton"];
    backButton.frame = CGRectMake(0, 0, image.size.width, image.size.height);
    [backButton setImage:image forState:UIControlStateNormal];
    [backButton addTarget:self
                   action:@selector(back)
         forControlEvents:UIControlEventTouchUpInside];
    //[backButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:backButton];
    [self.navigationItem setLeftBarButtonItem:item];
    UINavigationBar *bar = self.navigationController.navigationBar;
    [bar setBarTintColor:[UIColor whiteColor]];
    [self removeBottomLineInNavigation];
    if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
        CGRect statusBarViewFrame = CGRectMake(0, -20, self.view.frame.size.width, 20);
        UIView *statusBarView = [[UIView alloc] initWithFrame:statusBarViewFrame];
        statusBarView.backgroundColor=[UIColor whiteColor];
        [self.navigationController.navigationBar addSubview:statusBarView];
        self.navigationController.navigationBar.translucent = NO;
    }
}

// 移除UINavigationBar底部的黑线
- (void)removeBottomLineInNavigation {
    NSArray *subViews = [self.navigationController.navigationBar subviews];
    if ([subViews count] > 0) {
        UIView *view = subViews[0];
        NSArray *ssbviews = [view subviews];
        NSInteger count = [ssbviews count];
        if (count > 0) {
            for (NSInteger i=0; i<count; i++) {
                UIView *ssbView = ssbviews[i];
                if ([ssbView isKindOfClass:[UIImageView class]]) {
                    [ssbView removeFromSuperview];
                }
            }
        }
    }
}

-(void)setTitle:(NSString *)title {
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0 , 100, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];  //设置Label背景透明
    titleLabel.font = [UIFont systemFontOfSize:17];  //设置文本字体与大小
    titleLabel.textColor = [UIColor whiteColor];  //设置文本颜色
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = title;  //设置标题
    self.navigationItem.titleView = titleLabel;
}

- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
}

-(UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}



@end
